<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
// ------------------------------------------------------------------------

/**
 * String cut
 * Cut a string with given number of characters
 * @author	Nghia Ho
 * @access	public
 * @param	string original string
 * @param	integer	number of characters
 * @return	string
 */
if ( ! function_exists('trim_slashes'))
{
	function cut_str($str,$num){            
		$patterns = array('/<\/p>(\s*)<p>/Uism','/<br>/','/<br \/>/');
		$tmpStr = preg_replace($patterns, '\n', $str);
		$str = empty($tmpStr) ? $str : $tmpStr;
                $str = strip_tags($str);
               
		$num = $num-1;
		if($num>=(strlen($str)-1)) return str_replace('\n', '<br />', $str);

		while($str[$num]!=' '&&$num<(strlen($str)-1)){
			$num++;
		}
                
		return str_replace('\n', '<br />', substr($str,0,$num)).'...';
	}
}	